package com.hp.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hp.mapper.UsersMapper;
import com.hp.pojo.Users;
import com.hp.service.IUsersService;

@Service
@Transactional(readOnly = true)
public class UsersService implements IUsersService {

	@Resource
	private UsersMapper usersMapper;

	/**
	 * 查询所有用户
	 */
	@Override
	public List<Users> findUsers() {
		// TODO Auto-generated method stub
		return usersMapper.findUsers();
	}
	
	/**
	 * 分页查询用户信息
	 */
	@Override
	public PageInfo<Users> findPageInfo(PageInfo<Users> page,Users users) {
		// TODO Auto-generated method stub
		//1\调用pageHelper.startPage方法
		//注意地方，当前startPage()方法后面必须要跟查询数据的方法
		PageHelper.startPage(page.getPageNum(), page.getPageSize());
		
		//2\查询用户信息
		List<Users> list=usersMapper.findUsersLike(users);
		
		//3、把查询到的用户信息放到pageInfo对象中
		PageInfo<Users> pageInfo=new PageInfo<Users>(list,page.getPageSize());
		return pageInfo;
	}

	/**
	 * 添加
	 */
	@Transactional(propagation = Propagation.REQUIRED)
	public void insertUsers(Users users) {
		// TODO Auto-generated method stub
		usersMapper.insertUsers(users);
	}
	
	/**
	 * 通过id获取
	 */
	@Override
	public Users getUserById(Integer id) {
		// TODO Auto-generated method stub
		return usersMapper.getUserById(id);
	}

	/**
	 * 删除
	 */
	@Transactional(propagation = Propagation.REQUIRED)
	public void deleteUsersById(Users users) {
		// TODO Auto-generated method stub
		usersMapper.deleteUsersById(users);
	}

	/**
	 * 修改
	 */
	@Transactional(propagation = Propagation.REQUIRED)
	public void updateUsersById(Users users) {
		// TODO Auto-generated method stub
		usersMapper.updateUsersById(users);
	}





}
